﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Utils;

public partial class Theme_3_Channel :PowerCreator.LMS.Web.Base.WebBasePage
{
    PowerCreator.LMS.Web.Channel.Channel opChannel = new PowerCreator.LMS.Web.Channel.Channel();
    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
        {
            PowerCreator.LMS.Common.Script.Script.Alert(this, "msg", config.GetLanagerValueByKey("theme_Channel_LoginMsg", PowerCreator.LMS.Language.LanagetItemType.Page));
            return;
        }
        this.Title = config.GetLanagerValueByKey("theme_menu_Broadcast", PowerCreator.LMS.Language.LanagetItemType.Page);
        if (!IsPostBack)
        {
            BinderChannel();
        }
    }
    protected override void InitPage()
    {


        btn_Download.Text = GetLanageValueByKey("web_Channel_gv_c6", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }


    private void BinderChannel()
    {
        string ActiveClassIds = opChannel.GetActiveClassIDs();
        string search = "status > 0 and ChannelName not like '%_Student' and ID not in (" + ActiveClassIds + ")";
        DataTable dt = opChannel.QueryChannel(search);
        dt.Columns.Add("IsShuang");   //双视频,0不是，1是
        dt.Columns.Add("ChannelUrl");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            dt.Rows[i]["IsShuang"] = "0";
            string search1 = string.Format("status > 0 and ID not in (" + ActiveClassIds + ") and ChannelName like '{0}_Student'", dt.Rows[i]["ChannelName"]);
            DataTable dt1 = opChannel.QueryChannel(search1);
            if (dt1.Rows.Count >= 1)
            {
                dt.Rows[i]["IsShuang"] = "1";
            }

            int i_Flag = int.Parse(dt.Rows[i]["status"].ToString());
            int u_LOWORD = PowerCreator.LMS.Web.Channel.ChannelUtils.LOWORD(i_Flag);
            int u_HIWORD = PowerCreator.LMS.Web.Channel.ChannelUtils.HIWORD(i_Flag);

            if (PowerCreator.LMS.Web.Config.WebConfig.IsUseWeGe)
            {
                if (u_LOWORD != 2)
                {
                    if (u_HIWORD != 2)
                    {
                        dt.Rows[i].Delete();
                    }
                    else
                    {
                        dt.Rows[i]["ChannelUrl"] = "ChannelCommetNew.aspx?urltype=leftup&ContentID=" + dt.Rows[i]["ContentID"].ToString() + "&ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&type=Vedio&Title=" + dt.Rows[i]["Title"].ToString() + "&Author=" + dt.Rows[i]["Author"].ToString() + "&Description=" + dt.Rows[i]["Description"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();

                    }
                }
                else
                {
                    if (u_HIWORD != 2)
                    {
                        dt.Rows[i]["ChannelUrl"] =  "ChannelCommetNew.aspx?urltype=right&ContentID=" + dt.Rows[i]["ContentID"].ToString() + "&ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&Title=" + dt.Rows[i]["Title"].ToString() + "&Author=" + dt.Rows[i]["Author"].ToString() + "&Description=" + dt.Rows[i]["Description"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();
                    }
                    else
                    {
                        dt.Rows[i]["ChannelUrl"] = "ChannelCommetNew.aspx?urltype=all&ContentID=" + dt.Rows[i]["ContentID"].ToString() + "&ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&Title=" + dt.Rows[i]["Title"].ToString() + "&Author=" + dt.Rows[i]["Author"].ToString() + "&Description=" + dt.Rows[i]["Description"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();
                    }
                }

                if (dt.Rows[i]["IsShuang"].ToString() == "1")
                    dt.Rows[i]["ChannelUrl"] =  "ChannelCommetNew.aspx?urltype=dual&ContentID=" + dt.Rows[i]["ContentID"].ToString() + "&ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&Title=" + dt.Rows[i]["Title"].ToString() + "&Author=" + dt.Rows[i]["Author"].ToString() + "&Description=" + dt.Rows[i]["Description"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();
            }
            else
            {
                if (u_LOWORD != 2)
                {
                    if (u_HIWORD != 2)
                    {
                        dt.Rows[i].Delete();
                    }
                    else
                    {
                        dt.Rows[i]["ChannelUrl"] = WebUtils.WebRoot + "/web/broadcast/frmleftup.aspx?ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&type=Vedio" + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();

                    }
                }
                else
                {
                    if (u_HIWORD != 2)
                    {
                        dt.Rows[i]["ChannelUrl"] = WebUtils.WebRoot + "/web/broadcast/frm000.aspx?ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();
                    }
                    else
                    {
                        dt.Rows[i]["ChannelUrl"] = WebUtils.WebRoot + "/web/broadcast/Content.aspx?ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&Title=" + dt.Rows[i]["Title"].ToString() + "&Author=" + dt.Rows[i]["Author"].ToString() + "&Description=" + dt.Rows[i]["Description"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();
                    }
                }

                if (dt.Rows[i]["IsShuang"].ToString() == "1")
                    dt.Rows[i]["ChannelUrl"] = WebUtils.WebRoot + "/web/broadcast/dual/content.aspx?ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();

            }
        }
        rpt_Channel.DataSource = dt;
        rpt_Channel.DataBind();
    }
    protected void btn_Download_Click(object sender, EventArgs e)
    {
        PowerCreator.LMS.Common.Script.Script.RedirectURL(PowerCreator.LMS.Common.Utils.WebUtils.WebRoot + "/web/broadcast/download/LivePlayer.rar");
    }
}
